package com.huangwenshuo.futurestarschoolmanagement.controller;


import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.CoursewareDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.enums.RequestStateEnum;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.FoldersVO;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.Result;
import com.huangwenshuo.futurestarschoolmanagement.service.CoursewareService;
import com.huangwenshuo.futurestarschoolmanagement.service.FolderService;
import com.huangwenshuo.futurestarschoolmanagement.utils.ResUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huangwenshuo
 * @since 2021-03-07
 */
@RestController
@RequestMapping("/folder")
public class FolderController {

    @Autowired
    private FolderService folderService;

    @GetMapping("getFliesByUid")
    public Result getFliesByUid(Integer uid){
        List<FoldersVO> foldersVOS = null;
        try {
            foldersVOS = folderService.getFliesByUid(uid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),foldersVOS,"添加成功");
    }

    @PostMapping("addFo")
    public Result addFo(CoursewareDto.CPage page){
        try {
            folderService.addFo(page);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "" + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"添加成功");
    }
}

